package com.hw01.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result<String> handlerHttpException(HttpServletRequest request, Exception e) {
        e.printStackTrace();
        String servletPath = request.getServletPath();
        log.error(">>> 请求路径: " + servletPath + " 出现错误, 错误信息: ");
        log.error(e.getMessage());
        return Result.error("服务器错误", e.getMessage());
    }

}